#include <stdio.h>
#include <graph.h>

#include "\mylib\getkbd.h"
#include "\mylib\getstuff.h"


int UpperCase(int Nr, getField *FieldP, char *Str, int Pos, int c)
	{
	if (Nr != 1 || c != kFNKEY(1))
		return(c);
	for ( ; Pos > 0 ; Pos--, Str++)
		*Str = toupper(*Str);
	return(getUPDATE);
	}


int PruefZif(int Nr, getField *FieldP, char *Str, int Pos, int c)
	{
	char *p;
	int Anz, Sum;
	bool Fakt2;

	if (Nr != 1 || c != kFNKEY(1))
		return(c);
	Sum = 0;
	Fakt2 = TRUE;
	Anz = 0;
	for (p = Str + Pos - 1 ; p >= Str ; p--)
		{
		if (!isdigit(*p))
			continue;
		if (Fakt2)
			if (*p >= '5')
				Sum += 2 * (*p - '0') - 10 + 1;
			else
				Sum += 2 * (*p - '0');
		else
			Sum += *p - '0';
		Fakt2 = !Fakt2;
		if (++Anz == 6)
			return((1000 - Sum) % 10 + '0');
		}
	return(c);
	}


bool Check(getField *p, int cur, int new)
	{
	_settextposition(10,60);
	printf("%d %d    ", cur, new);
	return(TRUE);
	}


void main()
	{
	char Test[100] = "Test";
	int i, en, Field;
	long l;
	double d;
	bool b;

	_clearscreen( _GCLEARSCREEN );
	getInit(70, "Ja", "Nein", 1, 7, 5, 15);
	getClear();
	getDefineString(Test, 10, 5, 99, Check);
	getDefineInt(&i, 10, 10, 4, getFLAGFILL0, Check);
	getDefineLong(&l, 20, 10, 10, getFLAGNONEG, Check);
	getDefineDouble(&d, 10, 12, 10, 0, Check);
	getDefineBool(&b, 10, 14, Check);
	getDefineEnum(&en, 10, 16,
				  " \ta\taa\tab\tag\tba\taa a\tbc\tb\txxxxx\tAFG", Check);
	i = 234;
	l = -654321;
	d = 3.1415926;
	b = FALSE;
	en = 2;
	for (Field = 1 ; Field <= 6 ; Field++)
		getWriteField(Field);
	while (getRead(1, PruefZif) != kESC)
		;
	}



